﻿<template>
  <div>
    <!--  退货单 -->
    <a-card :bordered="false" :bodyStyle="tstyle">
      <div class="table-page-search-wrapper" v-if="hasPerm('WmsGoodsReturnOrder:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="单据编号">
                <a-input v-model="queryParam.no" allow-clear placeholder="请输入单据编号"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="供应商编码">
                <a-input v-model="queryParam.vendorcode" allow-clear placeholder="请输入供应商编码"/>
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="供应商名称">
                  <a-input v-model="queryParam.vendorname" allow-clear placeholder="请输入供应商名称"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="公司名称">
                  <a-input v-model="queryParam.companyname" allow-clear placeholder="请输入公司名称"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="仓管员">
                  <a-input v-model="queryParam.warehouseKeepername" allow-clear placeholder="请输入仓管员"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="仓储中心">
                  <a-input v-model="queryParam.warehouseCentername" allow-clear placeholder="请输入仓储中心"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="退货状态">
                  <a-select :allowClear="true" style="width: 100%" v-model="queryParam.goodsReturnStatus" placeholder="请选择退货状态">
                    <a-select-option v-for="(item,index) in goodsReturnStatusData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <!-- :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" -->
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.id"
        >
        <template class="table-operator" slot="operator" v-if="hasPerm('WmsGoodsReturnOrder:add')" >
          <a-button type="info" v-if="hasPerm('sysExcelTemplate:importExcel')" icon="upload" @click="$refs.excelForm.index()">
            导入
          </a-button>
          <a-button type="info" v-if="hasPerm('wmsGoodsReturnOrder:exportExcel')" icon="download" @click="wmsGoodsReturnOrderToExcel()">
            导出
          </a-button>
          <a-button type="primary" v-if="hasPerm('WmsGoodsReturnOrder:add')" icon="plus" @click="$refs.addForm.add()">新增退货单</a-button>
        </template>


        <template slot="index" slot-scope="text, record, index">{{ index + 1 }}</template>

        <template slot="linkSlot" slot-scope="text,record">
          <a @click="onOpenInfo(record)">{{ text }}</a>
        </template>


        <span slot="goodsReturnStatusscopedSlots" slot-scope="text">
          <a-tag :color="text===2?'#daa520':(text===1?'#cd5c5c':(text===3?'#add8e6':'#696969'))">{{ 'GoodsReturnStatus' | dictType(text) }}</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">

          
          <a v-if="hasPerm('WmsReceiptOrder:edit')" :class="[record.orderStatus == 1 ? 'disabled' : '']"
            @click="onDistributeBj(record)">退货</a>

          <!-- <a v-if="hasPerm('WmsGoodsReturnOrder:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('WmsGoodsReturnOrder:edit') & hasPerm('WmsGoodsReturnOrder:delete')"/>
          <a-popconfirm v-if="hasPerm('WmsGoodsReturnOrder:delete')" placement="topRight" title="确认删除？" @confirm="() => WmsGoodsReturnOrderDelete(record)">
            <a>删除</a>
          </a-popconfirm> -->
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />

      <detail-drawer ref="tableDetailDrawer" :visible.sync="infoVisible" :row="infoRow"  @postBjData="postBjData"/>

    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import { WmsGoodsReturnOrderPage, WmsGoodsReturnOrderDelete } from '@/api/modular/main/WmsGoodsReturnOrderManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
import DetailDrawer from './DetailDrawer.vue'

  export default {
    components: {
      STable,
      addForm,
      editForm,
    DetailDrawer
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
        {
          dataIndex: 'index',
          title: '序号',
          fixed: 'left',
          width: '60',
          scopedSlots: { customRender: 'index' },
          align: 'center'
        },
          {
            title: '单据编号',
            align: 'center',
            dataIndex: 'no',
          scopedSlots: { customRender: 'linkSlot' },
           minWidth:"100px"

          },
          {
            title: '创建日期',
            align: 'center',
            dataIndex: 'billdate',
           width:"150px"
          },
          {
            title: '供应商编码',
            align: 'center',
            dataIndex: 'vendorcode',
           minWidth:"100px"
          },
          {
            title: '供应商名称',
            align: 'center',
            dataIndex: 'vendorname',
           minWidth:"100px"
          },
          {
            title: '公司名称',
            align: 'center',
            dataIndex: 'companyname',
           minWidth:"100px"
          },
          {
            title: '仓管员',
            align: 'center',
            dataIndex: 'warehouseKeepername',
           minWidth:"100px"
          },
          {
            title: '仓储中心',
            align: 'center',
            dataIndex: 'warehouseCentername',
           minWidth:"100px"
          },
          {
            title: '退货状态',
            align: 'center',
            dataIndex: 'goodsReturnStatus',
            scopedSlots: { customRender: 'goodsReturnStatusscopedSlots' },
            minWidth:"100px"
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return WmsGoodsReturnOrderPage(Object.assign(parameter, this.queryParam)).then((res) => {
            this.$nextTick(()=>{
              if(res.data.rows && res.data.rows.length>0){
                this.onOpenInfo(res.data.rows[0]);
              }
            })
            return res.data
          })
        },
        goodsReturnStatusData: [],
        selectedRowKeys: [],
        selectedRows: [],
           //详情变量
      infoRow: {},
      infoVisible: false,
      postBjDataArr: []
      }
    },
    created () {
      if (this.hasPerm('WmsGoodsReturnOrder:edit') || this.hasPerm('WmsGoodsReturnOrder:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
      const goodsReturnStatusOption = this.$options
      this.goodsReturnStatusData = goodsReturnStatusOption.filters['dictData']('GoodsReturnStatus')
    },
    methods: {
      /**
       * 查询参数组装
       */
      switchingDate () {
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      WmsGoodsReturnOrderDelete (record) {
        WmsGoodsReturnOrderDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      //详情
    onOpenInfo(row) {
      this.infoVisible = true;
      this.infoRow = row;
      if(row){
       this.$refs.tableDetailDrawer.getList(row);
      }
    },
    // 选中的物料
    postBjData(data) {
      this.postBjDataArr = data
    },
    // 退货
    onDistributeBj(obj) {
      // if (obj.orderStatus !== 1 && obj.orderStatus !== 4) return false
      // if (obj.orderStatus == 1) return false



      // if(this.postBjDataArr.length<=0 || obj.id != this.postBjDataArr[0].orderId){
      //   this.$message.error('请选中此单据下的物料!')
      //   return
      // }
      // this.$confirm({
      //   title: '系统提示',
      //   content: '您将要进行报检任务的操作，确认要继续嘛？',
      //   okText: '确认',
      //   cancelText: '取消',
      //   onOk: () => {
      //     let param = {
      //       ...obj,
      //       dtls: this.postBjDataArr
      //     }
      //     WmsOrderBaojian(param).then(res => {
      //       if (res.success) {
      //         this.$message.success('操作成功')
      //         this.$refs.table.refresh()
      //       } else {
      //         this.$message.error('操作失败')
      //       }
      //     })
      //   }
      // })
    },
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
